<!-- 体系表单弹窗 -->
<form id="study-sys-form" lay-filter="study-sys-form" class="layui-form model-form">
    <input name="tcstid" type="hidden"/>
    <div class="layui-form-item">
        <label class="layui-form-label">体系名</label>
        <div class="layui-input-block">
            <input name="ttitle" placeholder="请输入体系名" type="text" class="layui-input"
                   lay-verify="required" required autocomplete="off"/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">描述</label>
        <div class="layui-input-block">
            <textarea name="tsdesc" id="tsdesc" placeholder="请输入描述内容" class="layui-textarea"></textarea>
        </div>
    </div>

    <div class="layui-form-item model-form-footer">
        <button class="layui-btn layui-btn-primary" ew-event="closeDialog" type="button">取消</button>
        <button class="layui-btn" lay-filter="study-sys-form-submit" lay-submit>保存</button>
    </div>
</form>

<script>
    layui.use(['layer', 'admin', 'form', 'formSelects','layedit'], function () {
        var layer = layui.layer;
        var admin = layui.admin;
        var form = layui.form;
        var formSelects = layui.formSelects;
        var layedit = layui.layedit;

        //富文本框
        var index = layedit.build('tsdesc',{
            height:180
        });
        // 回显数据
        var studySys = admin.getTempData('t_study_sys');
        $('#study-sys-form').attr('method', 'POST');
        if (studySys) {
            form.val('study-sys-form', studySys);
            layedit.setContent(index,studySys.tsdesc,false);
            $('#study-sys-form').attr('method', 'POST');
        }

        // 表单提交事件
        form.on('submit(study-sys-form-submit)', function (data) {
            data.field.tsdesc = layedit.getContent(index);
            layer.load(2);
            if (data.field.tcstid === ''){
                admin.req('api-study/teachingSys/insert', JSON.stringify(data.field), function (data) {
                    layer.closeAll('loading');
                    if (data.code === 0) {
                        layer.msg(data.msg, {icon: 1, time: 500});
                        admin.finishPopupCenter();
                    } else {
                        layer.msg(data.msg, {icon: 2, time: 500});
                    }
                }, 'POST');
            }else {
                admin.req('api-study/teachingSys/update', JSON.stringify(data.field), function (data) {
                    layer.closeAll('loading');
                    if (data.code === 0) {
                        layer.msg(data.msg, {icon: 1, time: 500});
                        admin.finishPopupCenter();
                    } else {
                        layer.msg(data.msg, {icon: 2, time: 500});
                    }
                }, 'POST');
            }

            return false;
        });
    });
</script>